package com.bq.gametrade.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.bean.TradingRecordsDetailsBean;
import com.bq.gametrade.bean.UserTradingRecordDetails;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author Feel on 2016/11/29 11:05
 */

public class TradingRecordsDetailsAdapter extends BaseAdapter {
    private ArrayList<TradingRecordsDetailsBean> items;
    private Context context;
    private String tradeType;

    public TradingRecordsDetailsAdapter(Context context, ArrayList<TradingRecordsDetailsBean> items,String tradeType) {
        this.context = context;
        this.items = items;
        this.tradeType = tradeType;
    }

    public void setData(ArrayList<TradingRecordsDetailsBean> items,String tradeType){
        this.items = items;
        this.tradeType = tradeType;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item_tradingrecorddetails,null);
            viewHolder.tradingTime = (TextView) convertView.findViewById(R.id.tv_trading_time);
            viewHolder.tradingCount = (TextView) convertView.findViewById(R.id.tv_trading_account);
            viewHolder.tradingMoney = (TextView) convertView.findViewById(R.id.tv_trading_money);
            viewHolder.tvUnitPrice = (TextView) convertView.findViewById(R.id.tv_unitPrice);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TradingRecordsDetailsBean bean = items.get(position);
        viewHolder.tradingTime.setText(bean.ctime);
        /**
         * tradingType:
         * 0 :买
         * 1：卖
         *
         */
        if(tradeType.equals("0")){
            viewHolder.tradingCount.setText("买 "+bean.ticket);
            viewHolder.tradingCount.setTextColor(context.getResources().getColor(R.color.red));
        }else if(tradeType.equals("1")){
            viewHolder.tradingCount.setText("卖 "+bean.ticket);
            viewHolder.tradingCount.setTextColor(context.getResources().getColor(R.color.green_28A71C));

        }
        viewHolder.tradingMoney.setText(bean.money.replace(",","")+" 元");


       return convertView;
    }

    class ViewHolder{
        TextView tradingTime;
        TextView tradingCount;
        TextView tradingMoney;
        TextView tvUnitPrice;
    }

}
